package com.idcard.readcard;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class ChooseTypeActivity extends AppCompatActivity {

    private String[] Permission = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.INTERNET, Manifest.permission.ACCESS_NETWORK_STATE};

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_read_type);

        Button nfcButton = findViewById(R.id.type_nfc);

        if (hasNFC(this)) {
            nfcButton.setVisibility(View.VISIBLE);
        } else {
            nfcButton.setVisibility(View.GONE);
        }

        nfcButton.setOnClickListener(v -> {
            startActivity(new Intent(this, NFCActivity.class));
        });

        findViewById(R.id.type_usb).setOnClickListener(v -> {
            startActivity(new Intent(this, UsbActivity.class));
        });

        findViewById(R.id.type_usb_tc).setOnClickListener(v -> {
            startActivity(new Intent(this, UsbTCActivity.class));
        });

        findViewById(R.id.type_port).setOnClickListener(v -> {
            startActivity(new Intent(this, PortActivity.class));
        });

        findViewById(R.id.type_sam).setOnClickListener(v -> {
            startActivity(new Intent(this, SamActivity.class));
        });

        new AlertDialog.Builder(this)
                .setTitle("温馨提示")
                .setMessage("测试使用的appid不可用于商业用途，商用appid请务必联系我司商务进行分配")
                .setCancelable(false)
                .setPositiveButton("确定", (dialog, which) -> dialog.dismiss())
                .show();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(Permission, 1000);
        }
    }


    private static boolean hasNFC(Context context) {
        PackageManager packageManager = context.getPackageManager();
        return packageManager.hasSystemFeature(PackageManager.FEATURE_NFC);
    }
}
